package com.zhanghu.backendZray.controller.permission;

import com.zhanghu.backendZray.annotation.MenuNeed;
import com.zhanghu.backendZray.manager.role.UserRoleMenuManager;
import com.zhanghu.backendZray.pojo.dto.ApiResponse;
import com.zhanghu.backendZray.pojo.request.userRole.UserRoleRequest;
import com.zhanghu.backendZray.service.UserRoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhangdong
 * @since 2024-07-20
 */
@RestController
@RequestMapping("/userRole")
@RequiredArgsConstructor
public class UserRoleController {
    private final UserRoleService userRoleService;
    private final UserRoleMenuManager userRoleMenuManager;

    /**
     * 获取当前用户角色
     */
    @MenuNeed(menuName = "user_manage")
    @GetMapping("getRoleByUserId")
    public ApiResponse<List<Integer>> getRoleByUserId(@RequestParam Integer userId) {
        return ApiResponse.ok(userRoleService.getRoleIdListByUserId(userId));
    }

    /**
     * 为用户配置角色
     * @param userRoleRequest
     * @return
     */
    @MenuNeed(menuName = "user_manage")
    @PostMapping("userRoleSetting")
    public ApiResponse userRoleSetting(@RequestBody UserRoleRequest userRoleRequest) {
        userRoleMenuManager.userRoleSetting(userRoleRequest);
        return ApiResponse.ok();
    }

}
